package com.bvgol.examples.dubbo.zk.api;

import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.JSONObject;
import lombok.Data;

import java.time.LocalDateTime;
import java.time.format.DateTimeFormatter;
import java.util.Date;
import java.util.List;

/**
 * @Classname HelloService
 * @Description TODO
 * @Date 2020/5/9 10:36
 * @Created by guochen
 */

public interface Hello3Service {
    String testDubbo();

    /**
     * 测试生产者间相互调用
     *
     * @return
     */
    String testDubbo2();

    String testDubbo3(String string);

    default String bye(String name) {
        return name + "-" + LocalDateTime.now().format(DateTimeFormatter.ofPattern("yyyy-mm-dd HH-mm-ss.SSS"));
    }

    default String bye(String name, Long age, Date date) {
        JSONObject jsonObject  = new JSONObject();
        jsonObject.put("name",name);
        jsonObject.put("age",age);
        jsonObject.put("date",date);
        return jsonObject.toJSONString() + "-" + LocalDateTime.now().format(DateTimeFormatter.ofPattern("yyyy-mm-dd HH-mm-ss.SSS"));
    }

    default String bye(Person person) {
        return JSON.toJSONString(person);
    }

    default String bye(List<String> names) {
        return JSON.toJSONString(names);
    }

    default String bye(String[] names) {
        return JSON.toJSONString(names);
    }

    default String byePersons(List<Person> persons) {
        return JSON.toJSONString(persons);
    }

    default String byePersons(Person[] persons) {
        return JSON.toJSONString(persons);
    }

    @Data
    public static class Person {
        private String name;

        private Long age;

        private Date birth;
    }
}
